from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()


#用户表
class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_name = db.Column(db.String(80), unique=True, nullable=False)
    user_password = db.Column(db.String(80), unique=False, nullable=False)
    phone = db.Column(db.String(11), unique=True)
    email = db.Column(db.String(120), unique=False)
    pimg = db.Column(db.Text, unique=False, default="img/userimg/img1.jpg")
    artical_count = db.Column(db.Integer, default=0)

    def __repr__(self):
        return '<User %r>' % self.user_name


#商品表
class Item(db.Model):
    __tablename__ = 'item'
    id = db.Column(db.Integer, primary_key=True)
    item_name = db.Column(db.String(80), unique=False)
    price = db.Column(db.Float, unique=False)
    author = db.Column(db.String(120), unique=False)
    image_url = db.Column(db.Text, unique=False)
    amount = db.Column(db.Integer, unique=False)

    def __repr__(self):
        return '<Item %r>' % self.item_name


#文章表
class Article(db.Model):
    __tablename__ = 'article'
    id = db.Column(db.Integer, primary_key=True)
    arc_name = db.Column(db.String(80), unique=False)
    arc_content = db.Column(db.Text, unique=False)
    arc_author = db.Column(db.String(120), unique=False)
    arc_url = db.Column(db.Text, unique=False, nullable=True, default='/img/article/default.jpg')
    arc_location = db.Column(db.Text, unique=False)
    arc_longtitude = db.Column(db.Float, unique=False)
    arc_latitude = db.Column(db.Float, unique=False)
    arc_click = db.Column(db.Integer, unique=False, default=0)
    arc_time = db.Column(db.DateTime, nullable=True)
    alike = db.Column(db.String(120), unique=True)

    def __repr__(self):
        return '<Article %r>' % self.arc_name


#评论表
class Comment(db.Model):
    __tablename__ = 'comment'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    comment_user_name = db.Column(db.String(80), nullable=False)
    comment_artical_title = db.Column(db.String(100), nullable=False)
    comment_con = db.Column(db.Text, nullable=False)

    def __repr__(self):
        return '<Comment %r>' % self.comment_con


class Oplog(db.Model):
    __tablename__ = 'oplog'
    id = db.Column(db.Integer, primary_key=True)
    op_user = db.Column(db.String(80), unique=False)
    op = db.Column(db.Text, unique=False)
    IP = db.Column(db.String(20), unique=False)
    op_date = db.Column(db.String(80), unique=False)


#管理员
class Admin(db.Model):
    __tablename__ = 'admin'
    id = db.Column(db.Integer, primary_key=True)
    user_name = db.Column(db.String(80), unique=True, nullable=False)

    def __repr__(self):
        return '<Admin %r>' % self.user_name


#关注表
class Attention(db.Model):
    __tablename__ = 'attention'
    id = db.Column(db.Integer, primary_key=True)
    user_name = db.Column(db.String(80), unique=False, nullable=False)
    attention_user = db.Column(db.String(80), unique=False, nullable=False)

    def __repr__(self):
        return '<Attention %r>' % self.user_name